package com.tarry.shop.search.mq.config;

import com.tarry.shop.constant.RabbitMQConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  RabbitMQ 配置
 */
@Configuration
public class RabbitMQConfig {

    /**
     *  创建商品队列
     * @return
     */
    @Bean
    public Queue goodsQueue(){
        return new Queue(RabbitMQConstant.GOODS_QUEUE,true,false,false);
    }

    /**
     *  创建商品交换机
     * @return
     */
    @Bean
    public TopicExchange goodsExchange(){
        return new TopicExchange(RabbitMQConstant.GOODS_EXCHANGE,true,false);
    }

    /**
     *  将商品队列和商品交换机进行绑定
     *
     * @return
     */
    @Bean
    public Binding goodsQueueToGoodsExchange(){
        return BindingBuilder.bind(goodsQueue()).to(goodsExchange()).with("goods.*");
    }
}
